'use strict';

const Controller = require('egg').Controller;

class indexController extends Controller {
  async index() {
    const { ctx } = this;
    ctx.logger.debug('我在debug');
    ctx.logger.info('我在输出info日志');
    ctx.logger.error(new Error('这个是个严重错误'));
    ctx.body = ctx.queries;// 获取多个的 url传值的
  }
  async home() {
    const { ctx } = this;
    const data = ctx.request.body; // 接收json数据
    console.log(data);
    ctx.body = data;
  }
  async curl() {
    const ctx = this.ctx;

    // 示例：请求一个 npm 模块信息
    const result = await ctx.curl('https://registry.npm.taobao.org/egg/latest', {
      // 自动解析 JSON response
      dataType: 'json',
      // 3 秒超时
      timeout: 3000,
    });

    ctx.body = {
      status: result.status,
      headers: result.headers,
      package: result.data,
    };
  }
  async curl_post() {
    const { ctx } = this;
    const result = await ctx.curl('https://httpbin.org/post', {
      method: 'POST',
      contentType: JSON,
      data: {
        name: '11',

      },
      dataType: JSON,
    });
    ctx.body = result;
  }
  async tianqi() {
    const { ctx } = this;
    const result = await ctx.curl('https://wis.qq.com/weather/common?source=pc&weather_type=observe%7Cforecast_1h%7Cforecast_24h%7Cindex%7Calarm%7Climit%7Ctips%7Crise&province=%E5%B9%BF%E4%B8%9C%E7%9C%81&city=%E6%B7%B1%E5%9C%B3%E5%B8%82&county=&callback=jQuery111302992647912134452_1596701073430&_=1596701073441', {
      method: 'POST',
      contentType: JSON,
      data: {
        source: 'pc',
        weather_type: 'observe|forecast_1h|forecast_24h|index|alarm|limit|tips|rise',
        province: '广东省',
        city: '深圳市',
        county: '',
        callback: 'jQuery111302992647912134452_1596701073430',
        _: 1596701073441,
      },
      dataType: JSON,
    });
    ctx.body = result;
  }
}

module.exports = indexController;
